/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef __ATC_TRANSFORMATION_HDR__
#define __ATC_TRANSFORMATION_HDR__

#define DBL_PAIR \
		std::pair< double, double >

#include <qmatrix.h>
//Added by qt3to4:
#include <Q3PointArray>
#include <stdexcept>

namespace atc {

	//
	// atc:transformation_error
	//

	struct transformation_error : public std::runtime_error {
		transformation_error( const std::string& msg ) 
			  : std::runtime_error( msg ) {}
	};


	//
	// atc::Transformation
	//

	class Transformation {

	public:
		Transformation();
		Transformation( const Transformation & );
		~Transformation();

	public:
		const QRect calculate( const QRect &, int );

	public:
		DBL_PAIR point ( double, double ) const;
		QPoint   qpoint( double, double ) const;
		QPoint   qpoint( const QPoint & ) const;
		double   length( double ) const;
		double   height( double ) const;

		Q3PointArray qpoints( const Q3PointArray & ) const;

		double   inverse_length( double ) const;
		DBL_PAIR inverse_point ( double, double ) const;
		QPoint   inverse_qpoint( double, double ) const;

	public:
		const Transformation invert() const;

	private:
		void init_matrix( const QRect &, const QRect & );

	private:
		QMatrix _mtx;

	}; 

	typedef DBL_PAIR TPoint;

};

#undef DBL_PAIR
#endif
